<html>
<head><meta charset="utf-8"><title>Rigging together ARMv8.3 PAC support in rustc? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html">Rigging together ARMv8.3 PAC support in rustc?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222935363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222935363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222935363">(Jan 15 2021 at 22:32)</a>:</h4>
<p>Hello, I'd like to try to rig together pointer authentication support within rustc. I tried this a few months ago, but failed.</p>
<ul>
<li>I'm using the apple/llvm-project, as it has full PAC support</li>
<li>PAC support involves emitting LLVM IR instructions around things like C function pointers, vtables, globals, etc<br>
<a href="https://github.com/apple/llvm-project/blob/apple/main/llvm/docs/PointerAuth.md">https://github.com/apple/llvm-project/blob/apple/main/llvm/docs/PointerAuth.md</a></li>
</ul>
<p>Where would the stuff relevant to this (as in, where the IR for things like that is emitted) in rustc_codegen_llvm be?</p>



<a name="222935623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222935623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222935623">(Jan 15 2021 at 22:35)</a>:</h4>
<p>I'm not sure. The way I normally try to find things in rustc is with ripgrep - if you know what the relevant LLVM functions are called, you could search for those.</p>



<a name="222935717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222935717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222935717">(Jan 15 2021 at 22:36)</a>:</h4>
<p>IIRC the main trouble I ran in to was related to constants/global initializers</p>



<a name="222935745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222935745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222935745">(Jan 15 2021 at 22:36)</a>:</h4>
<p>Which are initialized like this with PAC LLVM IR intrinsics </p>
<div class="codehilite" data-code-language="LLVM"><pre><span></span><code><span class="vg">@fp.ptrauth</span> <span class="p">=</span> <span class="k">constant</span> <span class="p">{</span> <span class="kt">i8</span><span class="p">*,</span> <span class="kt">i32</span><span class="p">,</span> <span class="kt">i64</span><span class="p">,</span> <span class="kt">i64</span> <span class="p">}</span>
                       <span class="p">{</span> <span class="kt">i8</span><span class="p">*</span> <span class="p">&lt;</span><span class="err">value</span><span class="p">&gt;,</span>
                         <span class="kt">i32</span> <span class="p">&lt;</span><span class="err">key</span><span class="p">&gt;,</span>
                         <span class="kt">i64</span> <span class="p">&lt;</span><span class="err">address</span> <span class="err">discriminat</span><span class="k">or</span><span class="p">&gt;,</span>
                         <span class="kt">i64</span> <span class="p">&lt;</span><span class="err">integer</span> <span class="err">discriminat</span><span class="k">or</span><span class="p">&gt;</span>
                       <span class="p">},</span> <span class="k">section</span> <span class="s">"llvm.ptrauth"</span>
</code></pre></div>



<a name="222935904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222935904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222935904">(Jan 15 2021 at 22:38)</a>:</h4>
<p>sorry - I don't know what 'constant' means in an LLVM context. Is this like a compile-time constant?</p>



<a name="222936003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222936003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222936003">(Jan 15 2021 at 22:39)</a>:</h4>
<blockquote>
<p>Authenticated Global Relocation</p>
<p>Intrinsics can be used to produce signed pointers dynamically, in code, but not for signed pointers referenced by constants, in, e.g., global initializers.</p>
<p>The latter are represented using a special kind of global describing an authenticated relocation (producing a signed pointer).</p>
<p>These special global must live in section 'llvm.ptrauth', and have a specific type.</p>
<div class="codehilite" data-code-language="LLVM"><pre><span></span><code><span class="vg">@fp.ptrauth</span> <span class="p">=</span> <span class="k">constant</span> <span class="p">{</span> <span class="kt">i8</span><span class="p">*,</span> <span class="kt">i32</span><span class="p">,</span> <span class="kt">i64</span><span class="p">,</span> <span class="kt">i64</span> <span class="p">}</span>
                       <span class="p">{</span> <span class="kt">i8</span><span class="p">*</span> <span class="p">&lt;</span><span class="err">value</span><span class="p">&gt;,</span>
                         <span class="kt">i32</span> <span class="p">&lt;</span><span class="err">key</span><span class="p">&gt;,</span>
                         <span class="kt">i64</span> <span class="p">&lt;</span><span class="err">address</span> <span class="err">discriminat</span><span class="k">or</span><span class="p">&gt;,</span>
                         <span class="kt">i64</span> <span class="p">&lt;</span><span class="err">integer</span> <span class="err">discriminat</span><span class="k">or</span><span class="p">&gt;</span>
                       <span class="p">},</span> <span class="k">section</span> <span class="s">"llvm.ptrauth"</span>
</code></pre></div>
<p>is equivalent to @fp.ptrauth being initialized with:</p>
<p><div class="codehilite" data-code-language="LLVM"><pre><span></span><code>  <span class="nv">%disc</span> <span class="p">=</span> <span class="k">call</span> <span class="kt">i64</span> <span class="vg">@llvm.ptrauth.blend.i64</span><span class="p">(</span><span class="kt">i64</span> <span class="p">&lt;</span><span class="err">address</span> <span class="err">discriminat</span><span class="k">or</span><span class="p">&gt;,</span> <span class="kt">i64</span> <span class="p">&lt;</span><span class="err">integer</span> <span class="err">discriminat</span><span class="k">or</span><span class="p">&gt;)</span>
  <span class="nv">%signed_fp</span> <span class="p">=</span> <span class="k">call</span> <span class="kt">i64</span> <span class="vg">@llvm.ptrauth.sign.i64</span><span class="p">(</span><span class="kt">i64</span> <span class="k">bitcast</span> <span class="p">(</span><span class="kt">i8</span><span class="p">*</span> <span class="p">&lt;</span><span class="err">value</span><span class="p">&gt;</span> <span class="k">to</span> <span class="kt">i64</span><span class="p">),</span> <span class="kt">i32</span> <span class="p">&lt;</span><span class="err">key</span><span class="p">&gt;,</span> <span class="kt">i64</span> <span class="nv">%disc</span><span class="p">)</span>
  <span class="nv">%fp_p_loc</span> <span class="p">=</span> <span class="k">bitcast</span> <span class="p">{</span> <span class="kt">i8</span><span class="p">*,</span> <span class="kt">i32</span><span class="p">,</span> <span class="kt">i64</span><span class="p">,</span> <span class="kt">i64</span> <span class="p">}*</span> <span class="vg">@fp.ptrauth</span> <span class="k">to</span> <span class="kt">i64</span><span class="p">*</span>
  <span class="k">store</span> <span class="kt">i64</span> <span class="nv">%signed_fp</span><span class="p">,</span> <span class="kt">i8</span><span class="p">*</span> <span class="nv">%fp_p_loc</span>
</code></pre></div><br>
</p>
</blockquote>



<a name="222936014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222936014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222936014">(Jan 15 2021 at 22:39)</a>:</h4>
<p>that's what the docs in the LLVM fork say</p>



<a name="222936083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222936083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222936083">(Jan 15 2021 at 22:40)</a>:</h4>
<p>ok I see, the fork added new LLVM functions? and you don't know how to call those functions through <code>rustc_llvm</code>?</p>



<a name="222936101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222936101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222936101">(Jan 15 2021 at 22:40)</a>:</h4>
<p>no, I had trouble with <em>where</em> to call these</p>



<a name="222936132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222936132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222936132">(Jan 15 2021 at 22:41)</a>:</h4>
<p>sorry if i'm being vague, i kind of just gave up on this a few months back, and am just now getting back to it</p>



<a name="222936149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222936149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222936149">(Jan 15 2021 at 22:41)</a>:</h4>
<p>nah you're good, I know nothing about codegen and am stumbling along as much as you are <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="222936216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222936216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222936216">(Jan 15 2021 at 22:42)</a>:</h4>
<p>probably <a href="https://rustc-dev-guide.rust-lang.org/backend/codegen.html">https://rustc-dev-guide.rust-lang.org/backend/codegen.html</a> will be more helpful than I can be</p>



<a name="222938716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222938716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222938716">(Jan 15 2021 at 23:06)</a>:</h4>
<p>that doesn't really describe the innards though, sadly</p>



<a name="222946424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222946424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222946424">(Jan 16 2021 at 00:47)</a>:</h4>
<p>In <code>rustc_codegen_llvm/src/callee.rs</code>, what's <code>llfn</code>?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">llfn</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">llfn</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cx</span><span class="p">.</span><span class="n">get_declared_value</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sym</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// Create a fn pointer with the new signature.</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">llptrty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fn_abi</span><span class="p">.</span><span class="n">ptr_to_llvm_type</span><span class="p">(</span><span class="n">cx</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>A pointer to a function, right?</p>



<a name="222946754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222946754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222946754">(Jan 16 2021 at 00:52)</a>:</h4>
<p>the function value itself.</p>



<a name="222946809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222946809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222946809">(Jan 16 2021 at 00:53)</a>:</h4>
<p>hm, it's the pointers that i need to sign.</p>



<a name="222946842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222946842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222946842">(Jan 16 2021 at 00:54)</a>:</h4>
<p>actually i don't even need to bother with "internal" functions (stuff that's in the same binary), it's calls to system libraries / dynamic libraries that i need to worry about</p>



<a name="222946886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222946886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> aspen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222946886">(Jan 16 2021 at 00:54)</a>:</h4>
<p>at least for now</p>



<a name="222948918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rigging%20together%20ARMv8.3%20PAC%20support%20in%20rustc%3F/near/222948918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rigging.20together.20ARMv8.2E3.20PAC.20support.20in.20rustc.3F.html#222948918">(Jan 16 2021 at 01:23)</a>:</h4>
<p>I think for your purposes that's either the function value (symbol) itself or maybe it ptrcasted to a plain pointer.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>